package com.qf.business.student.controller;

import com.qf.commons.event.apply.producer.EventUtils;
import com.qf.data.base.r.R;
import com.qf.data.base.r.Rs;
import com.qf.feign.classes.ClsFeign;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
@RestController
@RequestMapping("/stu")
@Slf4j
public class StuController {

    @Autowired
    private ClsFeign clsFeign;

    @Autowired
    private LoadBalancerFeignClient client;

    @RequestMapping("/get")
    @GlobalTransactional
//    @Trace
    public R queryStu(Integer sid){
//        System.out.println("------>" + TraceContext.traceId());

        if (sid == 1)
            EventUtils.send("get-stu", "这是随便写的一条消息！" + sid);
        else if (sid == 2)
            EventUtils.send("save-stu", "这是随便写的一条消息！" + sid);
        else if (sid == 3)
            EventUtils.sendDelay("get-stu", "这是随便写的一条消息！" + sid, 5, TimeUnit.SECONDS);
        else if (sid == 4)
            EventUtils.sendDelay("get-stu", "这是随便写的一条消息！" + sid, 10, TimeUnit.SECONDS);
        else if (sid == 5)
            EventUtils.sendDelay("get-stu", "这是随便写的一条消息！" + sid, 8, TimeUnit.SECONDS);

//        Long uid = UserInfo.getUid();
//        System.out.println("登录的用户信息：" + uid);
//
//        log.info("当前feign的核心调用接口：{}", client.getDelegate());
//        log.info("调用了学生查询的服务：{}", sid);
//        String data = (String) clsFeign.query(sid).result();
//        log.info("接收到班级的响应：{}", data);
//        if (sid == 1)
//            System.out.println(1/0);
        return Rs.create("小明");
    }
}
